<?php

require_once 'Zend/Exception.php';
require_once './application/core/Lang/LangCore.php';

///
/// Controller de base pour ADN
///
class ControllerBase extends Zend_Controller_Action
{

    // Objet de redirection
    protected $_redirector = null;
    public $_path;
    public $_urlBase;
    public $_idClient;
    public $_isConnect;
    private $_session;

    // Initialisation
    public function init()
    {
        $this->_redirector = $this->_helper->getHelper('Redirector');
        $this->_path = dirname($_SERVER['SCRIPT_FILENAME']);
        $this->_urlBase = dirname($_SERVER['SCRIPT_NAME']);
        if ($this->_urlBase == '/' || $this->_urlBase == '\\')
            $this->_urlBase = '';
        $this->view->urlBase = $this->_urlBase;
        $this->_idClient = md5(session_id());
        $l = new LangCore($this);
        $l->putConstant();
    }

    protected function renderTabControl()
    {
        $this->_helper->layout->disableLayout();
    }

    protected function renderLogin()
    {
        $this->_helper->layout->setLayout('login');
    }

    // Methode de verification de la connexion
    // A appeler dans les methodes des descendant au besoin
    protected function verifConnexion()
    {
        $this->_session = new Zend_Session_Namespace('session');
        if (!isset($this->_session->idClient))
        {
            $this->_redirector->gotoSimple('connexion', '');
        }
    }

    protected function noRender()
    {
        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->getHelper('layout')->disableLayout();
    }

}
